package com.testfileupload.uploadimg.design.chainofresponsibility.defind;

public abstract class Handler {
    private Handler nextHanler;

    public void setNextHanler(Handler nextHanler) {
        this.nextHanler = nextHanler;
    }

    //每个处理者必须对请求做处理
    public final Response handleMessage(Request request) {
        Response response = null;
        //判断是否是自己的处理级别
        if (this.getHandlerLevel().equals(request.getRequestLevel())) {
            response = this.echo(request);
        }else {
            if (this.nextHanler!=null){
                this.handleMessage(request);
            }else {
                //没有适当的处理者
            }
        }
        return response;
    }
    //每个处理器都必须实现处理任务
    protected abstract Response echo(Request request);

    //每个处理者都有一个处理级别
    protected abstract Level getHandlerLevel();

}
